<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Use the 'eventHandlers' option and the 'update' event for refreshing areas when the user click on
        them</title>
    <style type="text/css">
        body {
            color: #5d5d5d;
            font-family: Helvetica, Arial, sans-serif;
        }

        h1 {
            font-size: 30px;
            margin: auto;
            margin-top: 50px;
        }

        .container {
            max-width: 800px;
            margin: auto;
        }

        /* Specific mapael css class are below
         * 'mapael' class is added by plugin
        */

        .mapael .mapTooltip {
            position: absolute;
            background-color: #fff;
            moz-opacity: 0.70;
            opacity: 0.70;
            filter: alpha(opacity=70);
            border-radius: 10px;
            padding: 10px;
            z-index: 1000;
            max-width: 200px;
            display: none;
            color: #343434;
        }

        /* For all zoom buttons */
        .mapael .zoomButton {
            background-color: #fff;
            border: 1px solid #ccc;
            color: #000;
            width: 15px;
            height: 15px;
            line-height: 15px;
            text-align: center;
            border-radius: 3px;
            cursor: pointer;
            position: absolute;
            top: 0;
            font-weight: bold;
            left: 10px;

            -webkit-user-select: none;
            -khtml-user-select : none;
            -moz-user-select: none;
            -o-user-select : none;
            user-select: none;
        }

        /* Reset Zoom button first */
        .mapael .zoomReset {
            top: 10px;
        }

        /* Then Zoom In button */
        .mapael .zoomIn {
            top: 30px;
        }

        /* Then Zoom Out button */
        .mapael .zoomOut {
            top: 50px;
        }

        .mapael .map {
            position: relative;
        }
    </style>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"
            charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js" charset="utf-8"></script>
    <script src="../../js/jquery.mapael.js" charset="utf-8"></script>
    <script src="../../js/maps/france_departments.js" charset="utf-8"></script>
    <script src="../../js/maps/world_countries.js" charset="utf-8"></script>
    <script src="../../js/maps/usa_states.js" charset="utf-8"></script>

    <script type="text/javascript">
        $(function () {
            $(".mapcontainer").mapael({
                map: {
                    name: "france_departments",
                    zoom: {
                        enabled: true
                    },
                    defaultArea: {
                        attrs: {
                            fill: "#5ba4ff",
                            stroke: "#99c7ff",
                            cursor: "pointer"
                        },
                        attrsHover: {
                            animDuration: 0
                        },
                        text: {
                            attrs: {
                                cursor: "pointer",
                                "font-size": 10,
                                fill: "#000"
                            },
                            attrsHover: {
                                animDuration: 0
                            }
                        },
                        eventHandlers: {
                            click: function (e, id, mapElem, textElem) {
                                var newData = {
                                    'areas': {}
                                };
                                if (mapElem.originalAttrs.fill == "#5ba4ff") {
                                    newData.areas[id] = {
                                        attrs: {
                                            fill: "#0088db"
                                        }
                                    };
                                } else {
                                    newData.areas[id] = {
                                        attrs: {
                                            fill: "#5ba4ff"
                                        }
                                    };
                                }
                                $(".mapcontainer").trigger('update', [{mapOptions: newData}]);
                            }
                        }
                    }
                },
                areas: {
                    "department-29": {
                        text: {
                            content: "dblclick",
                            position: "top"
                        },
                        attrs: {
                            fill: "#0088db"
                        },
                        tooltip: {
                            content: "Finistère (29)"
                        },
                        eventHandlers: {
                            click: function () {
                            },
                            dblclick: function (e, id, mapElem, textElem) {
                                var newData = {
                                    'areas': {}
                                };
                                if (mapElem.originalAttrs.fill == "#5ba4ff") {
                                    newData.areas[id] = {
                                        attrs: {
                                            fill: "#0088db"
                                        }
                                    };
                                } else {
                                    newData.areas[id] = {
                                        attrs: {
                                            fill: "#5ba4ff"
                                        }
                                    };
                                }
                                $(".mapcontainer").trigger('update', [{mapOptions: newData}]);
                            }
                        }
                    }
                }
            });
        });
    </script>

</head>

<body>
<div class="container">

    <h1>Use the 'eventHandlers' option and the 'update' event for refreshing areas when the user click on them</h1>

    <div class="mapcontainer">
        <div class="map"><span>Alternative content for the map</span>

        </div>
    </div>

    <p><b>All example for jQuery Mapael are available <a href="https://www.vincentbroute.fr/mapael/">here</a>.</b></p>

</div>


</body>
</html>